package com.rui1024.servlet;

import com.rui1024.dao.MenuDao;
import com.rui1024.dao.OrderDao;
import com.rui1024.dao.impl.MenuDaoImpl;
import com.rui1024.dao.impl.OrderDaoImpl;
import com.rui1024.pojo.Diary;
import com.rui1024.pojo.Menu;
import com.rui1024.pojo.Specialty;
import com.rui1024.util.JDBCUtil;
import com.rui1024.util.PageUtil;
import com.rui1024.util.PropertiesUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/MenuServlet")
public class MenuServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");// 设置为统一编码

        OrderDao od = new OrderDaoImpl();
        MenuDao menua = new MenuDaoImpl();
        JDBCUtil jdbcUtil = new JDBCUtil();
        Connection con = null;

        try {
            con = jdbcUtil.getCon();
            List<Menu> list = menua.readMenu(con);
            int listTotalSum= od.ordersSumTotal(con);

            request.setAttribute("listTotalSum", listTotalSum);// 把数据存起来
            request.setAttribute("menu", list);// 把数据存起来
            request.getRequestDispatcher("menu.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                jdbcUtil.closeCon(con);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }



    }


